﻿//GB/Z 29014.3 ISYC 307-13-可转位全直径刀片柄连接立铣刀

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{
    class ISYC_307_13_F81
    {
        public static void ISYC_307_F81_H(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            double scale = 1;
            double OAL = 38.53 * scale;
            double LPR = 24.83 * scale;
            double LU = 10.28 * scale;
            double DCONMS = 7.39 * scale;
            double LS = 20.77 * scale;
            double LH = 17.22 * scale;
            double APMX = 4.37 * scale;
            double BD = 8.29 * scale;
            double DC = 8.64 * scale;

            //点---------------------------------------------------------------------------------------------
            //第一部分
            //中心线
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + OAL, v1.Y);
            Vector2 v3 = new Vector2(v2.X - APMX, v2.Y + (5.1 / 8.64) * DC);
            Vector2 v4 = new Vector2(v3.X, -v3.Y);

            //轮廓
            Vector2 v5 = new Vector2(v1.X, v1.Y + (3.25 / 7.39) * DCONMS);
            Vector2 v6 = new Vector2(v1.X + (0.77 / 20.77) * LS, v1.Y + DCONMS / 2.0);
            Vector2 v7 = new Vector2(v1.X + LS, v6.Y);
            Vector2 v8 = new Vector2(v7.X + (OAL - LS - LH), v1.Y + BD / 2.0);
            Vector2 v9 = fun.Inters(v3, v4, v8, fun.Polar(v8, 0, OAL));
            Vector2 v10 = new Vector2(v9.X, -v9.Y);
            Vector2 v11 = new Vector2(v8.X, -v8.Y);
            Vector2 v12 = new Vector2(v7.X, -v7.Y);
            Vector2 v13 = new Vector2(v6.X, -v6.Y);
            Vector2 v14 = new Vector2(v5.X, -v5.Y);
            Vector2 v15 = new Vector2(v9.X - (1.22 / 17.22) * LH, v9.Y);
            Vector2 v16 = new Vector2(v15.X, -v15.Y);
            Vector2 v17 = new Vector2(v6.X + (8.66 / 20.77) * LS, v6.Y + (4.99 / 7.39) * DCONMS);
            Vector2 v18 = new Vector2(v17.X + (2.39 / 20.77) * LS, v17.Y);
            Vector2 v19 = new Vector2(v18.X + (1.72 / 20.77) * LS, v18.Y - (1.72 / 20.77) * LS);
            Vector2 v20 = fun.Inters(v19, fun.Polar(v19, -90 * pi / 180, OAL), v1, v2);
            Vector2 v21 = new Vector2(v19.X, -v19.Y);
            Vector2 v22 = new Vector2(v18.X, -v18.Y);
            Vector2 v23 = new Vector2(v17.X, -v17.Y);

            //第二部分
            //中心线
            Vector2 v24 = new Vector2(v2.X + (25.91 / 38.53) * OAL, v2.Y);
            Vector2 v25 = new Vector2(v24.X + (10.53 / 38.53) * OAL, v2.Y);
            Vector2 v24_1 = new Vector2(v24.X + fun.CalDistance(v24, v25) / 2.0, v2.Y);
            Vector2 v26 = new Vector2(v24_1.X, v24_1.Y + (5.1 / 8.64) * DC);
            Vector2 v27 = new Vector2(v26.X, -v26.Y);

            //轮廓
            Vector2 v28_1 = fun.Inters1(v3, new Vector2(v4.X - 0.0001, v4.Y), fun.DrawArc4(v16, (8.64 / 8.29) * BD / 2.0, v15, 1), 1);
            Vector2 v28 = new Vector2(v24_1.X - (0.3 / 8.64) * DC, v28_1.Y);
            Vector2 v29 = new Vector2(v24_1.X + (0.3 / 8.64) * DC, v9.Y);
            Vector2 v30 = fun.rotatePoint_Changed(v24_1, v28, 180);
            Vector2 v31 = fun.rotatePoint_Changed(v24_1, v29, 180);

            //标注点 
            Vector2 v32 = new Vector2(v6.X + (9.2 / 20.77) * LS, v6.Y);
            Vector2 v33 = new Vector2(v13.X - (3.46 / 20.77) * LS, v13.Y - (3.9 / 7.39) * DCONMS);
            Vector2 v34 = new Vector2(v3.X + (10.85 / 38.53) * OAL, v3.Y + (12.18 / 8.64) * DC);
            Vector2 v35 = new Vector2(v2.X + (13.31 / 38.53) * OAL, v2.Y);

            //作图部分-----------------------------------------------------------------------
            //中心线
            Line line1 = new Line(v1, v2);
            line1.Layer = centre;
            line1.Linetype = Linetype.Center;
            line1.LinetypeScale = 1;
            dxf.AddEntity(line1);

            Line line2 = new Line(v3, v4);
            line2.Layer = centre;
            line2.Linetype = Linetype.Center;
            line2.LinetypeScale = 1;
            dxf.AddEntity(line2);

            Line line3 = new Line(v24, v25);
            line3.Layer = centre;
            line3.Linetype = Linetype.Center;
            line3.LinetypeScale = 5;
            dxf.AddEntity(line3);

            Line line4 = new Line(v26, v27);
            line4.Layer = centre;
            line4.Linetype = Linetype.Center;
            line4.LinetypeScale = 5;
            dxf.AddEntity(line4);

            //第一部分
            //轮廓
            LwPolyline polyline1 = new LwPolyline();
            polyline1.Vertexes.Add(new LwPolylineVertex(v1));
            polyline1.Vertexes.Add(new LwPolylineVertex(v5));
            polyline1.Vertexes.Add(new LwPolylineVertex(v6));
            polyline1.Vertexes.Add(new LwPolylineVertex(v7));
            polyline1.Vertexes.Add(new LwPolylineVertex(v8));
            polyline1.Vertexes.Add(new LwPolylineVertex(v9));
            fun.PolyFill(dxf, polyline1, 0.3, contour);

            var arc1 = fun.DrawArc4(v10, BD / 2.0, v9, 1);
            fun.drawBArc(dxf, arc1, 0.3, contour);

            LwPolyline polyline2 = new LwPolyline();
            polyline2.Vertexes.Add(new LwPolylineVertex(v10));
            polyline2.Vertexes.Add(new LwPolylineVertex(v11));
            polyline2.Vertexes.Add(new LwPolylineVertex(v12));
            polyline2.Vertexes.Add(new LwPolylineVertex(v13));
            polyline2.Vertexes.Add(new LwPolylineVertex(v14));
            polyline2.Vertexes.Add(new LwPolylineVertex(v1));
            fun.PolyFill(dxf, polyline2, 0.3, contour);

            LwPolyline polyline3 = new LwPolyline();
            polyline3.Vertexes.Add(new LwPolylineVertex(v6));
            polyline3.Vertexes.Add(new LwPolylineVertex(v13));
            fun.PolyFill(dxf, polyline3, 0.3, contour);

            LwPolyline polyline4 = new LwPolyline();
            polyline4.Vertexes.Add(new LwPolylineVertex(v7));
            polyline4.Vertexes.Add(new LwPolylineVertex(v12));
            fun.PolyFill(dxf, polyline4, 0.3, contour);

            LwPolyline polyline5 = new LwPolyline();
            polyline5.Vertexes.Add(new LwPolylineVertex(v8));
            polyline5.Vertexes.Add(new LwPolylineVertex(v11));
            fun.PolyFill(dxf, polyline5, 0.3, contour);

            var arc2 = fun.DrawArc4(v16, (8.64 / 8.29) * BD / 2.0, v15, 1);
            fun.drawBArc(dxf, arc2, 0.3, contour);

            //虚线
            LwPolyline polyline6 = new LwPolyline();
            polyline6.Vertexes.Add(new LwPolylineVertex(v17));
            polyline6.Vertexes.Add(new LwPolylineVertex(v18));
            polyline6.Vertexes.Add(new LwPolylineVertex(v19));
            polyline6.Vertexes.Add(new LwPolylineVertex(v21));
            polyline6.Vertexes.Add(new LwPolylineVertex(v22));
            polyline6.Vertexes.Add(new LwPolylineVertex(v23));
            polyline6.Linetype = Linetype.Dashed;
            polyline6.LinetypeScale = 1;
            polyline6.Layer = refin;
            dxf.AddEntity(polyline6);

            //第二部分
            //轮廓
            LwPolyline polyline14 = new LwPolyline();
            polyline14.Vertexes.Add(new LwPolylineVertex(v28));
            polyline14.Vertexes.Add(new LwPolylineVertex(v29));
            polyline14.Vertexes.Add(new LwPolylineVertex(v30));
            polyline14.Vertexes.Add(new LwPolylineVertex(v31));
            polyline14.Vertexes.Add(new LwPolylineVertex(v28));
            fun.PolyFill(dxf, polyline14, 0.3, contour);

            fun.drawcircle(dxf, v24_1, BD / 2.0, 0.3, contour);

            //标注---------------------------------------------------------------------------
            double height = 2 * scale;
            double arrowsize = 1 * scale;
            double exline = 0.5 * scale;

            //坐标系
            fun.Axis(dxf, v1, 180, 270, "", "", "PCS", 0.2 * scale, height * 0.5, 0);
            fun.Axis(dxf, v20, 180, 270, "", "", "MCS", 0.2 * scale, height * 0.5, 0);
            fun.Axis(dxf, v33, 180, 270, "Z", "Y", "X", 0.2 * scale, height * 0.5, 0);

            //DCONMS
            fun.dimrot1(dxf, v6, v13, 90, LS * 0.3, 0.1, height, arrowsize, exline, "DCONMS", "", "");

            //LS
            fun.dimrot1(dxf, v14, v12, 180, DCONMS * 2, 0.1, height, arrowsize, exline, "LS", "", "");

            //LH
            fun.dimrot1(dxf, v11, v2, 180, DCONMS * 2 + Math.Abs(Math.Abs(v12.Y - v14.Y) / 2.0 - Math.Abs(v11.Y - v2.Y) / 2.0), 0.1, height, arrowsize, exline, "LH", "", "");

            //OAL
            fun.dimrot1(dxf, v5, v2, 0, DCONMS * 3, 0.1, height, arrowsize, exline, "OAL", "", "");

            //LPR
            fun.dimrot1(dxf, v19, v2, 0, DCONMS * 1.8, 0.1, height, arrowsize, exline, "LPR", "", "");

            //LU
            fun.dimrot1(dxf, new Vector2(v8.X + (6.95 / 24.92) * LPR, v8.Y), v2, 0, DCONMS * 1, 0.1, height, arrowsize, exline, "LU", "", "");

            //BD
            fun.dimrot1(dxf, v9, v10, -90, OAL * 0.25, 0.1, height, arrowsize, exline, "BD", "", "");

            //DC
            fun.dimrot1(dxf, v28_1, new Vector2(v28_1.X, -v28_1.Y), -90, OAL * 0.4, 0.1, height, arrowsize, exline, "DC", "", "");

            //箭头
            //FDP
            fun.jt1(dxf, v34, -90, 5, 1, "FDP", height);

            //CCMS
            fun.jt1(dxf, v32, 100, 5, 1, "CCMS", height);

            //A
            fun.jt1(dxf, v35, 0, 5, 1, "A", height);

            //字符
            fun.text(dxf, new Vector2(v26.X - (2.45 / 11.13) * DCONMS, v26.Y + (2.24 / 11.13) * DCONMS), height, "View A");

            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}
